/*和助管信息的增删查改*/
require.config({
    paths: {
        "common": "../common/common"
    }
});
define(['common'], function(common, defaultStr) {
    var baseUrl = common.defaultStr();
    var zhuguan_url = {
        "addZhuguan": baseUrl + "/base/stu/insertStuToAst.do",
        "queryZhuguan": baseUrl + "/base/stu/list.do",
        "delZhuguan": baseUrl + "/base/stu/delete.do",
        "editZhuguan": baseUrl + "/base/stu/update.do",
        "queryStu": baseUrl + "/base/stu/searchStudent.do",
    };
    /*查询助管信息*/
    function queryZG(query) {
        return $.ajax({
            type: "POST",
            url: zhuguan_url.queryZhuguan,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(query),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }
    /*从学生列表添加助管信息，多条*/
    function addZhuguan(data) {
        return $.ajax({
            type: "POST",
            url: zhuguan_url.addZhuguan,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(data),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }
    /*删除一条助管信息*/
    function delZhuguan(data) {
        return $.ajax({
            type: "POST",
            url: zhuguan_url.delZhuguan,
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );;
    }
    /*编辑一条助管信息*/
    function editZhuguan(data) {
        return $.ajax({
            type: "POST",
            url: zhuguan_url.editZhuguan,
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function handleSessionTimeOut(data) {
        if (data && data.retcode === '202') {
            location.reload();
        }
    }
    return {
        addZG: addZhuguan,
        delZG: delZhuguan,
        editZG: editZhuguan,
        queryZG,
        baseUrl
    }
})
